package org.hxyjs.config;

import org.hxyjs.cache.RedisCache;
import org.springframework.cache.Cache;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

public class CacheConfig {
    @Bean("cacheManager")
    public SimpleCacheManager getCacheManager(RedisTemplate<Serializable,Serializable> redisTemplate){
        SimpleCacheManager cacheManager = new SimpleCacheManager();
        RedisCache redisCache = new RedisCache();
        redisCache.setRedisTemplate(redisTemplate);
        redisCache.setName("myCache");//重点在这 这里的名字 和 使用缓存的方法的注解对应的匹配
        Set set = new HashSet<Cache>();
        set.add(redisCache);
        cacheManager.setCaches(set);
        return cacheManager;
    }
}
